home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / SED15.ARJ / SED.LST < prev    next >
File List  |  1991-09-22  |  25KB  |  661 lines

  1.  
  2.  
  3.  
  4.    SED(1)                      USER DOCUMENTATION                       SED(1)
  5.  
  6.  
  7.    NAME
  8.       sed - the stream editor
  9.  
  10.    SYNOPSIS
  11.       sed [-n] [-g] [-e script] [-f sfilename] [filename ]
  12.  
  13.    DESCRIPTION
  14.    sed reads each filename line by line, edits each line according to a script
  15.    of commands  as specified  by the  -e and -f arguments  and then copies the
  16.    edited line to the standard output.
  17.  
  18.    OPTIONS
  19.    The -e  option supplies  a single  edit command  from the next argument; if
  20.    there are  several of  these they  are executed in the order in  which they
  21.    appear. If  there is  just one  -e option  and no -f's, the -e  flag may be
  22.    omitted. An  -f option causes commands to be taken from the file sfilename;
  23.    if there  are several   of these they are  executed in the order  in  which
  24.    they appear;  -e and  -f commands may be mixed. The script or sfilename can
  25.    be adjacent  to the  -e or  -f or  can be  the next argument on the command
  26.    line.   The -g  option causes sed to act as though every substitute command
  27.    in the  following script  has a  g suffix.   The  -n option  suppresses the
  28.    default output.
  29.  
  30.    SCRIPTS
  31.    A script  consists of  one or  more sed  commands of  the  following  form:
  32.         [address[,address]] function [arguments]     
  33.    Normally sed cyclically copies a line of input into a  current text buffer,
  34.    then applies  in sequence all commands whose addresses select that line and
  35.    then copies  the buffer  to standard  output and clears the buffer.  The -n
  36.    option suppresses normal output so that only commands which do output (e.g.
  37.    p) cause  any writing  to occur.   Also,  some commands (n, N) do their own
  38.    line reads,  and some  others (o, d, D) cause all commands following in the
  39.    script to  be skipped  (the D  command also  suppresses the clearing of the
  40.    current text  buffer that  would normally  occur before  the  next  cycle).
  41.    There is  also a  second buffer (called the 'hold space' that can be copied
  42.    or appended to or from or swapped with the current text buffer.
  43.  
  44.    ADDRESSES
  45.    An address  is: a  decimal number  (which matches  that numbered line where
  46.    line numbers start at 1 and run cumulatively across files), or a '$' (which
  47.    matches the last line of input), or a '/regular expression/' (which matches
  48.    any line  satisfying the expression. The following rules govern the address
  49.    matching:
  50.  
  51.       * A command line with no addresses selects every input line.
  52.  
  53.       * A command line with one address selects every input line that  matches
  54.         that address.
  55.  
  56.       * A command line with two addresses selects the inclusive range from the
  57.         first input line that matches the first address up to and including
  58.         the next input that matches the second. (If the second address is a
  59.         number less than or equal to the line number first  selected, only one
  60.         line is selected.) Once the second address is matched sed starts
  61.  
  62.  
  63.  
  64.    h**2 Documentation          21 September 1991                             1
  65.  
  66.  
  67.  
  68.  
  69.  
  70.    SED(1)                      USER DOCUMENTATION                       SED(1)
  71.  
  72.  
  73.         looking for the first one again; thus, any number of these ranges will
  74.         be matched.
  75.  
  76.       * The second address may be in the form of '+number'.  This means that
  77.         the command will stay selected for number lines after the first
  78.         address is satisfied.
  79.  
  80.       * \?regular expression? where ? is any character is identical to
  81.         /regular expression/.
  82.  
  83.       * The negation operator '!' preceding a function makes that function
  84.         apply to every line not selected by the address(es).
  85.  
  86.    FUNCTIONS
  87.    In the  following list  of  functions,  the  maximum  number  of  addresses
  88.    permitted for  each function  is indicated  in parentheses.    An  argument
  89.    denoted 'text' consists of one or more lines,  with all but the last ending
  90.    with '\' to hide the newline. A command with this type argument must be the
  91.    last on  any command  line or  -e argument. Otherwise multiple commands may
  92.    appear on  a line  separated by  ';' characters.   A  command  may  have  a
  93.    trailing comment  indicated by  a '#' character. Comment lines begin with a
  94.    '#'.   Backslashes in  text are  treated as  described in 'escape sequences
  95.    below; they   may  be  used  to  protect  initial  whitespace  against  the
  96.    stripping that  is done  on every  line of the script.  An argument denoted
  97.    'label', 'rfile'  or 'wfile'  (which specify  labels or file names)  is not
  98.    processed for  'escape sequences'.  Therefore a  ';' or  '#' terminates the
  99.    label or  file name. This simplifies entering DOS style paths. Each 'wfile'
  100.    is created  before processing  begins.   There can  be at  most 10 distinct
  101.    'wfile' arguments.
  102.  
  103.    (1) a text      Append the 'text' on output before reading the next input
  104.                    line.
  105.  
  106.    (2) b [label]   Branch to the ':' command with the given 'label'.  If no
  107.                    'label' is  given, branch to the end of the script.
  108.  
  109.    (2) c text      Change lines by deleting the current text buffer and at the
  110.                    end of the address range, place 'text' on the output.
  111.                    Start the next input cycle.
  112.  
  113.    (2) d           Delete the current text buffer. Start the next input cycle.
  114.  
  115.    (2) D           Delete the first line of the current text buffer (all
  116.                    characters up to the first newline). Start the next input
  117.                    cycle.
  118.  
  119.    (2) g           Replace the contents of the current text buffer with the
  120.                    contents  of the hold space.
  121.  
  122.    (2) G           Append the contents of the hold space to the current text
  123.                    buffer.
  124.  
  125.    (2) h           Copy the current text buffer into the hold space.
  126.  
  127.  
  128.  
  129.  
  130.    h**2 Documentation          21 September 1991                             2
  131.  
  132.  
  133.  
  134.  
  135.  
  136.    SED(1)                      USER DOCUMENTATION                       SED(1)
  137.  
  138.  
  139.    (2) H           Append a copy of the current text buffer to the hold space.
  140.  
  141.    (1) i text      Insert the 'text' on the standard output.
  142.  
  143.    (2) l [w[file]] List current text buffer on standard output or to a file if
  144.                    the  -w option follows. Non ASCII printable characters are
  145.                    expanded as shown in the 'escape sequence' section below.
  146.  
  147.    (2) n           Copy the current text buffer to standard output. Read the
  148.                    next line of input into it. The current line number
  149.                    changes.
  150.  
  151.    (2) N           Append the next line of input to the current text buffer,
  152.                    inserting an embedded newline between the two. The current
  153.                    line number changes.
  154.  
  155.    (2) p           Copy the current text buffer to the standard output.
  156.  
  157.    (2) P           Copy the first line of the current text buffer (all
  158.                    characters up to the first newline) to standard output.
  159.  
  160.    (1) q           Quit. Perform any pending outputs (a or r commands) and
  161.                    terminate sed.
  162.  
  163.    (1) r rfile     Read the contents of 'rfile'. Place them on the output
  164.                    before reading the next input line.
  165.  
  166.    (2) s /regular expression/replacement/flags
  167.                    Substitute the 'replacement' for instances of the 'regular
  168.                    expression' in the current text buffer.  Any character may
  169.                    be used instead of '/'. In the 'regular expression' and in
  170.                    the 'replacement' text \1 - \9 are used to indicate the nth
  171.                    subexpression indicated by a '\(...\)' expression in the
  172.                    'regular expression'.  In the replacement text an & may be
  173.                    used to indicate the entire matched expression. If the
  174.                    replacement text consists only of the a single '%'
  175.                    character, then a copy of the replacement text for the
  176.                    previous s command is used as the replacement text for this
  177.                    command.  'Flags' are any of the following options, with
  178.                    the following provisos: if present w must be the last one;
  179.                    only the last of either p or P is used; and  only the last
  180.                    'n} is used.
  181.  
  182.                      g - Global. Substitute for all nonoverlapping instances
  183.                        of the  'RE' rather than just the first one.
  184.  
  185.                      p - Print the current text buffer if a replacement was
  186.                        made.
  187.  
  188.                      P - Print the first line of the current text buffer if a
  189.                        replacement was made.
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.    h**2 Documentation          21 September 1991                             3
  197.  
  198.  
  199.  
  200.  
  201.  
  202.    SED(1)                      USER DOCUMENTATION                       SED(1)
  203.  
  204.  
  205.                      w[wfile] -  Append the current text buffer to the file
  206.                        argument as in a w command if a replacement is made.
  207.                        Standard output is used if no file argument is given.
  208.  
  209.                      n - Where n can be 1 through 512. Perform only the nth
  210.                        replacement. If  g is also set or the -g option is
  211.                        selected, this option means that the nth and all
  212.                        succeeding substitutions should be performed.
  213.  
  214.    (2) t [label]   Branch to the ':' command with the given 'label' if any  s
  215.                    commands made any substitutions since the most recent read
  216.                    of an input line or execution of a t or  T.  If no 'label'
  217.                    is given, branch to the end of the script.
  218.  
  219.    (2) T [label]   Branch to the ':' command with the given 'label' if no s
  220.                    commands have succeeded since the last input line or t or T
  221.                    command. Branch to the end of the script if no 'label' is
  222.                    given.
  223.  
  224.    (2) w [wfile]   Write the current text buffer to 'wfile'. If no 'wfile' is
  225.                    given standard output is used.
  226.  
  227.    (2) W [wfile]   Write the first line of the current text buffer to 'wfile'.
  228.                    If no 'wfile' is given standard output is used.
  229.  
  230.    (2) x           Exchange the contents of the current text buffer and hold
  231.                    space.
  232.  
  233.    (2) y /string1/string2/
  234.                    Translate. Replace each occurrence of a character in
  235.                    string1 with the corresponding character in string2.  The
  236.                    '/' may be any character not in 'string1' or 'string2'.
  237.                    The lengths of the two strings must be equal.
  238.  
  239.    (2) ! function  All-but.  Apply the function (or group, if function is '{')
  240.                    only to lines not selected by the address(es).
  241.  
  242.    (0) : label     This command defines a label for b T and t commands.
  243.  
  244.    (1) =           Write a line containing the current line number to the
  245.                    standard output.
  246.  
  247.    (2) {           Execute the following commands through a matching '}' only
  248.                    when the current line matches the address or address range
  249.                    given.
  250.  
  251.    (0) }           The { command marks the end of a grouping started by a '{'.
  252.  
  253.    (0)             An empty command is ignored.
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.    h**2 Documentation          21 September 1991                             4
  263.  
  264.  
  265.  
  266.  
  267.  
  268.    SED(1)                      USER DOCUMENTATION                       SED(1)
  269.  
  270.  
  271.    ESCAPE SEQUENCES    
  272.    The following escape sequences are used to represent unprintable characters
  273.    in 'text',  'regular expressions'  and 'replacement' text. It is ignored in
  274.    'labels' and 'file's.  If the character following the '\ 'is not list below
  275.    the '\'  causes the  character to  be quoted  during script  input.  The  l
  276.    command also uses this convention.
  277.  
  278.              \a   - bell       (ASCII 07)  
  279.              \b   - backspace  (ASCII 08)  
  280.              \e   - escape     (ASCII 27)  
  281.              \f   - formfeed   (ASCII 12)  
  282.              \n   - newline    (ASCII 10)  
  283.              \r   - return     (ASCII 13)  
  284.              \t   - tab        (ASCII 09)  
  285.              \v   - verticaltab(ASCII 11)  
  286.              \xhh - the ASCII character corresponding to 2 hex digits hh.     
  287.              \\   - the backslash itself.  
  288.  
  289.    REGULAR EXPRESSIONS ('REs')   
  290.    Regular expressions  can be  built up from the following "single-character"
  291.    'RE's:
  292.  
  293.    c         Any ordinary character not listed below. An ordinary character
  294.              matches itself.
  295.  
  296.    \          Backslash. When followed by a special character the 'RE' matches
  297.              the "quoted character" as listed in 'Escape Sequences' above.  A
  298.              backslash followed by one of <,>,(,),{,} or 0...9 represents an
  299.              'operator' in a regular expression, as described below.
  300.  
  301.    .         Dot. Matches any single character except the NEWLINE at the end
  302.              of a line.
  303.  
  304.    ^         Carat. As the leftmost character in an 'RE' this constrains the
  305.              pattern to be an anchored match.  That is it must match anchored
  306.              at the first character in the line.  In any other position the ^
  307.              is an ordinary character.
  308.  
  309.    $         The dollar sign as the rightmost character in an 'RE' matches the
  310.              NEWLINE at the end of the line. At any other position the $ is an
  311.              ordinary character.
  312.  
  313.    ^RE$      This requires the 'RE' to match the entire buffer.
  314.  
  315.    [c...]    A nonempty string of characters enclosed by square brackets
  316.              matches any single character in the string except the NEWLINE at
  317.              the end of the string.  If the first character of the string is a
  318.              caret (^), then the 'RE' matches any character not in the string
  319.              except the NEWLINE at the end of the string. A '-' sign may be
  320.              used to express ranges of characters. For example the range '[0-
  321.              9]' is equivalent to the string '[0123456789]'. The '-' is
  322.              treated as an ordinary character if it occurs in the string at a
  323.              position that can not be part of a range. This construct is
  324.              called 'set definition'.
  325.  
  326.  
  327.  
  328.    h**2 Documentation          21 September 1991                             5
  329.  
  330.  
  331.  
  332.  
  333.  
  334.    SED(1)                      USER DOCUMENTATION                       SED(1)
  335.  
  336.  
  337.    \{m\}
  338.    \{m,\}
  339.    \{m,n\\}  When any of these constructs follow an ordinary character, a dot,
  340.              a 'set  definition' or the '\n' construct. This construct matches
  341.              the previous construct  for a range of occurrences.  At least  m
  342.              occurrences will be matched and at most  n.  "\{m,\}" matches at
  343.              least m occurrences and "\{m}" matches exactly m.
  344.  
  345.    *         When this follows an ordinary character, a dot, a 'set
  346.              definition' or the '\n' construct, this 'RE' matches 0 or more
  347.              occurrences of that construct. This pattern is called a
  348.              'closure'.
  349.  
  350.    +         This pattern is similar to the star above but matches one or more
  351.              occurrences of the previous construct.
  352.  
  353.    \<        The sequence \< in an 'RE' requires that the scan position in the
  354.              line must be immediately following a character that can not be
  355.              part  of a "word" and immediately preceding a character that can
  356.              be part of a "word".  In this context a "word" is any sequence of
  357.              upper and lowercase letters, a numeral [0-9] or the underscore
  358.              character (_).
  359.  
  360.    \>        The sequence \> in an 'RE' requires that the scan position in the
  361.              line must be immediately following a character that can be part
  362.              of a "word" and immediately preceding a character that can not be
  363.              part of a "word".
  364.  
  365.    \(...\)   An 'RE' enclosed between the character sequences \( and \)
  366.              matches whatever the unadorned 'RE' matches, but saves the string
  367.              matched by the enclosed RE in a numbered substring register.
  368.              There can be up to nine such substrings in an 'RE', and the
  369.              parenthesis operators can be nested.
  370.  
  371.    \n        Match the contents on the nth substring register. When nested
  372.              substrings are present, 'n' is determined by counting the
  373.              occurrences of \( starting from the left.
  374.  
  375.    //        The empty 'RE' (//) is equivalent to the last 'RE' encountered in
  376.              the input processing.
  377.  
  378.    ERROR MESSAGES 
  379.    The following error messages may appear during the compilation phase of sed
  380.    processing all cause sed to terminate:
  381.  
  382.    sed: bad expression 'hh' -- The escape sequence of "\x" did was  not
  383.         followed by two hex digits
  384.  
  385.    sed: bad value for match count on s command 'command' -- A maximum value of
  386.         512 is allowed for 'n' on an s command.
  387.  
  388.    sed: cannot create 'file' -- The listed output file could not be opened
  389.  
  390.  
  391.  
  392.  
  393.  
  394.    h**2 Documentation          21 September 1991                             6
  395.  
  396.  
  397.  
  398.  
  399.  
  400.    SED(1)                      USER DOCUMENTATION                       SED(1)
  401.  
  402.  
  403.    sed: cannot open command-file 'file' -- The 'file' on an -f argument could
  404.         not be opened
  405.  
  406.    sed: command "command" has trailing garbage -- Command was not terminated
  407.         properly
  408.  
  409.    sed: duplicate label 'label' -- The indicated 'label' appeared on more than
  410.         one ':' command
  411.  
  412.    sed: error processing: 'argument' -- The 'argument' is incorrect either a
  413.         file name was missing or the g or n options had trailing garbage
  414.  
  415.    sed: garbled address 'command' -- Improper 'regular expression' in an
  416.         address, line number in an address  or + used in first address
  417.  
  418.    sed: garbled command 'command' -- Error in the construction of the 'regular
  419.         expression' or 'replacement' in an  s command, an ill-formed y command
  420.         or a 'null' character was found
  421.  
  422.    sed: no addresses allowed for 'command -- The end of group (}) and label
  423.         command (:), can not have addresses
  424.  
  425.    sed: no argument for -e -- The -e option did not have a 'script'
  426.  
  427.    sed: no such command as 'command' -- The function in the 'command' was
  428.         illegal
  429.  
  430.    sed: only one address allowed for 'command' -- The a i q r and = commands
  431.         allow only one address
  432.  
  433.    sed: range error in set 'command -- A [...'x'-'y'...] construct was  found
  434.         where y<x
  435.  
  436.    sed: RE too long: 'command' -- Internal buffer overflow while processing a
  437.         'character set'
  438.  
  439.    sed: too many commands, last was 'command' -- A maximum of 200 commands are
  440.         allowed
  441.  
  442.    sed: too many labels: 'command' -- A maximum of 50 labels are allowed
  443.  
  444.    sed: too many line numbers 'command' -- More than 256 different line
  445.         numbers were used or more than 50 + addresses were used
  446.  
  447.    sed: too many w files 'command' -- A maximum of 10 output files is allowed
  448.  
  449.    sed: too many {'s 'command' -- A '{' command did not have a matching '}'
  450.         command
  451.  
  452.    sed: too many }'s 'command' -- A '}' command appeared before an opening '{'
  453.         command
  454.  
  455.    sed: too much text: 'command' -- The internal command text buffer
  456.         overflowed processing the command
  457.  
  458.  
  459.  
  460.    h**2 Documentation          21 September 1991                             7
  461.  
  462.  
  463.  
  464.  
  465.  
  466.    SED(1)                      USER DOCUMENTATION                       SED(1)
  467.  
  468.  
  469.    sed: undefined label 'label' -- The listed 'label' was never defined on a :
  470.         command
  471.  
  472.    sed: unknown flag 'option' -- The listed 'option' is not allowed on the
  473.         invoking line for sed
  474.  
  475.    The following warning may be displayed during compilation:
  476.  
  477.    sed: Label not used 'label' -- The listed 'label' was defined but never
  478.         referenced.
  479.  
  480.    During the actual editing the following fatal errors can occur:
  481.  
  482.    sed: append too long after line 'number' -- An A, G, H, or N command
  483.         created a line in the buffer longer than 4000 characters
  484.  
  485.    sed: cannot open 'file' -- The r command could not open 'file'
  486.  
  487.    sed: infinite branch loop at line 'number' -- More than 50 branches were
  488.         taken without the editing of the line completing
  489.  
  490.    sed: line too long at line 'number' -- While the s command was performing a
  491.         substitution the line length exceeded 4000 characters
  492.  
  493.    sed: RE bad code 'code' -- An internal processing error has occurred while
  494.         matching a 'regular expression'
  495.  
  496.    sed: too many appends after line 'number' -- An append command caused more
  497.         than 20 reads and appends for the given line
  498.  
  499.    sed: too many reads after line 'number' -- A read command caused more than
  500.         20 reads and appends for the give line
  501.  
  502.    BUGS
  503.    I tried  to fix  every problem  I could find, but I believe the follow bugs
  504.    still exist in this version:
  505.  
  506.       * The getline routine can overflow the buffer before checking for
  507.         overflow
  508.  
  509.       * I still do not know exactly what the D command should do
  510.  
  511.       * Strange options on the s command are allowed
  512.  
  513.       * The handling of inrange for '{' commands
  514.  
  515.       * Error processing could be improved
  516.  
  517.       * All output files are overwritten even when there are errors
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526.    h**2 Documentation          21 September 1991                             8
  527.  
  528.  
  529.  
  530.  
  531.  
  532.    SED(1)                      USER DOCUMENTATION                       SED(1)
  533.  
  534.  
  535.    COMPATIBILITY
  536.    This version of sed is a modification of the Internet supplied GNU version.
  537.    That version  was reverse-engineered  from BSD  4.1 UNIX sed. The following
  538.    changes, modifications and improvements have been made:
  539.  
  540.       * There is no hidden length limit (40 in BSD sed) on 'wfile' names.
  541.  
  542.       * There is no limit (8 in BSD sed) on the length of 'labels'.
  543.  
  544.       * The exchange command now works for long pattern and hold spaces.
  545.  
  546.       * 'Escape sequences' are inhibited for both 'label's and 'filename's.
  547.  
  548.       * All commands not having a 'text' argument can be separated by ";" or
  549.         can have trailing comments (#)
  550.  
  551.       * a, c and i commands don't insist on a leading backslash  '\n' in the
  552.         text.
  553.  
  554.       * r and w commands do not insist on whitespace before the filename.
  555.  
  556.       * The g, P, p and 'n' options on s commands may be given in any order.
  557.  
  558.       * Escape sequences are valid in all contexts except file names and
  559.         labels.
  560.  
  561.       * The full range of characters are allowed all 256 values.
  562.  
  563.       * In an 'RE', '+' calls for 1...n repeats of the previous pattern.
  564.  
  565.       * The l command produces a different format than the UNIX sed.
  566.  
  567.       * The W command (write first line of pattern space to file).
  568.  
  569.       * The T command (branch on last substitution failed).
  570.  
  571.       * sed's error messages have been made more specific and informative and
  572.         cause processing to halt.
  573.  
  574.       * + allowed in the second address.
  575.  
  576.       * The empty RE "//" is allowed as a first address if a previous RE has
  577.         been compiled
  578.  
  579.       * The -e and -f command line options do not require their arguments to
  580.         be separate options.
  581.  
  582.       * If no arguments are given sed prints usage data.
  583.  
  584.       * In all contexts a blank file name means 'stdout'.
  585.  
  586.    This version  otherwise appears to be equivalent to the UNIX version on the
  587.    Sun4 computer.   That  is I  believe anything  that sed did on that system,
  588.    this version of sed will do the same on either a Sun4 or a PC under DOS. If
  589.  
  590.  
  591.  
  592.    h**2 Documentation          21 September 1991                             9
  593.  
  594.  
  595.  
  596.  
  597.  
  598.    SED(1)                      USER DOCUMENTATION                       SED(1)
  599.  
  600.  
  601.    anyone can really explain what sed is really supposed to do as explained in
  602.    the UNIX documentation I would appreciate the information.  The manual page
  603.    refers to  ed for  further details  which is  ambiguous  at  best  and  the
  604.    description I  read for  either the  D command  or the  options for  the  s
  605.    command were not understandable by me.
  606.  
  607.    I would appreciate any comments, suggestions and even bug reports.  I some-
  608.    times can  be reached on INTERNET (the fiscal year is almost over), but you
  609.    can always contact me by mail or phone  
  610.         Howard Helman (helman@elm.sdd.trw.com)  
  611.         Box 340   
  612.         Manhattan Beach, CA 90266     
  613.         213.372.5387 or after 11/1/91 310.372.538    
  614.  
  615.  
  616.  
  617.  
  618.  
  619.  
  620.  
  621.  
  622.  
  623.  
  624.  
  625.  
  626.  
  627.  
  628.  
  629.  
  630.  
  631.  
  632.  
  633.  
  634.  
  635.  
  636.  
  637.  
  638.  
  639.  
  640.  
  641.  
  642.  
  643.  
  644.  
  645.  
  646.  
  647.  
  648.  
  649.  
  650.  
  651.  
  652.  
  653.  
  654.  
  655.  
  656.  
  657.  
  658.    h**2 Documentation          21 September 1991                            10
  659.  
  660.  
  661.